package com.job.client.city.service.impl;

import com.job.client.city.constant.CityConstant;
import com.job.client.city.pojo.CityDefault;
import com.job.client.city.pojo.CityOrder;
import com.job.client.city.pojo.ProvinceDefault;
import com.job.client.city.service.CityService;
import com.job.client.common.result.AppHttpCode;
import com.job.client.common.result.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class CityServiceImpl implements CityService {
    @Autowired
    private MongoTemplate mongoTemplate;
    @Override
    public ResponseResult setDefault(List<ProvinceDefault> provinceDefaultList) {
        if(provinceDefaultList == null){
            return ResponseResult.ErrorResult(AppHttpCode.DATA_NULL);
        }
        mongoTemplate.insertAll(provinceDefaultList);
        return ResponseResult.OkResult();
    }

    @Override
    public ResponseResult setOrder(List<CityOrder> cityOrderList) {
        if(cityOrderList == null){
            return ResponseResult.ErrorResult(AppHttpCode.DATA_NULL);
        }
        mongoTemplate.insertAll(cityOrderList);
        return ResponseResult.OkResult();
    }
    @Override
    public ResponseResult setHot(List<CityDefault> cityDefaults) {
        if(cityDefaults == null){
            return ResponseResult.ErrorResult(AppHttpCode.DATA_NULL);
        }
        mongoTemplate.insertAll(cityDefaults);
        return ResponseResult.OkResult();
    }

    @Override
    public ResponseResult getHotAll() {
        List<CityDefault> all = mongoTemplate.findAll(CityDefault.class);
        if(all == null){
            return ResponseResult.ErrorResult(AppHttpCode.SERVICE_ERROR);
        }
        log.error("12456");
        return ResponseResult.OkResult(all);
    }

    @Override
    public ResponseResult getDefaultAll() {
        List<ProvinceDefault> all = mongoTemplate.findAll(ProvinceDefault.class);
        if(all == null){
            return ResponseResult.ErrorResult(AppHttpCode.SERVICE_ERROR);
        }
        return ResponseResult.OkResult(all);
    }

    @Override
    public ResponseResult getOrderAll() {
        List<CityOrder> all = mongoTemplate.findAll(CityOrder.class);
        if(all == null){
            return ResponseResult.ErrorResult(AppHttpCode.SERVICE_ERROR);
        }
        return ResponseResult.OkResult(all);
    }
}
